import java.io.*;
import java.nio.file.*;
import java.util.List;

public class RemoveBOM {
    public static void main(String[] args) {
        String sourceDir = "D:\\project_ALL\\ForeverLove\\LAgain\\LAgain\\src\\main\\java";
        try {
            Files.walk(Paths.get(sourceDir))
                .filter(path -> path.toString().endsWith(".java"))
                .forEach(RemoveBOM::removeBOM);
            System.out.println("BOM removal completed.");
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    
    private static void removeBOM(Path filePath) {
        try {
            byte[] content = Files.readAllBytes(filePath);
            if (content.length >= 3 && content[0] == (byte) 0xEF && content[1] == (byte) 0xBB && content[2] == (byte) 0xBF) {
                // BOM found, remove it
                byte[] newContent = new byte[content.length - 3];
                System.arraycopy(content, 3, newContent, 0, newContent.length);
                Files.write(filePath, newContent);
                System.out.println("Removed BOM from: " + filePath.getFileName());
            }
        } catch (IOException e) {
            System.err.println("Error processing file: " + filePath);
            e.printStackTrace();
        }
    }
}